<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/favicon.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon.png">
  <link rel="mask-icon" href="/images/favicon.png" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css">


<script id="hexo-configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    hostname: new URL('https://codz-me.vercel.app').hostname,
    root: '/',
    scheme: 'Muse',
    version: '7.7.1',
    exturl: false,
    sidebar: {"position":"right","display":"post","padding":18,"offset":12,"onmobile":false},
    copycode: {"enable":false,"show_result":false,"style":null},
    back2top: {"enable":true,"sidebar":false,"scrollpercent":false},
    bookmark: {"enable":false,"color":"#222","save":"auto"},
    fancybox: true,
    mediumzoom: false,
    lazyload: false,
    pangu: false,
    comments: {"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},
    algolia: {
      appID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    localsearch: {"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
    path: '',
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}
  };
</script>

  <meta name="description" content="Bug Not Found">
<meta property="og:type" content="website">
<meta property="og:title" content="Code Is Poetry">
<meta property="og:url" content="https://codz-me.vercel.app/page/2/index.html">
<meta property="og:site_name" content="Code Is Poetry">
<meta property="og:description" content="Bug Not Found">
<meta property="og:locale" content="zh_CN">
<meta property="article:author" content="laudukang">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://codz-me.vercel.app/page/2/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: true,
    isPost: false
  };
</script>

  <title>Code Is Poetry</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-meta">

    <div>
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Code Is Poetry</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
  </div>

  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-fw fa-user"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
        <li class="menu-item menu-item-commonweal">

    <a href="/404/" rel="section"><i class="fa fa-fw fa-heartbeat"></i>公益 404</a>

  </li>
  </ul>

</nav>
</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
        
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://codz-me.vercel.app/2016/09/25/java-cacerts-import-certificate/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/head.png">
      <meta itemprop="name" content="laudukang">
      <meta itemprop="description" content="Bug Not Found">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Code Is Poetry">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          
            <a href="/2016/09/25/java-cacerts-import-certificate/" class="post-title-link" itemprop="url">Java cacerts 证书库导入自签名证书</a>
        </h1>

        <div class="post-meta">
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2016-09-25 17:21:41 17:21:41" itemprop="dateModified" datetime="2016-09-25T17:21:41+08:00">2016-09-25 17:21:41</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Java/" itemprop="url" rel="index">
                    <span itemprop="name">Java</span>
                  </a>
                </span>
            </span>

          
            <span id="/2016/09/25/java-cacerts-import-certificate/" class="post-meta-item leancloud_visitors" data-flag-title="Java cacerts 证书库导入自签名证书" title="阅读次数">
                <span hidden class="leancloud-visitors-count"></span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>issue<br>JDK未导入自签名证书，调HTTPS接口会有如下错误</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.ssl.Alerts.getSSLException(Alerts.java:<span class="number">192</span>) at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:<span class="number">1949</span>) at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:<span class="number">302</span>) at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:<span class="number">296</span>) at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:<span class="number">1509</span>) at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:<span class="number">216</span>) at sun.security.ssl.Handshaker.processLoop(Handshaker.java:<span class="number">979</span>) at sun.security.ssl.Handshaker.process_record(Handshaker.java:<span class="number">914</span>) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:<span class="number">1062</span>) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:<span class="number">1375</span>) at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:<span class="number">747</span>) at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:<span class="number">123</span>) at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:<span class="number">82</span>) at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:<span class="number">140</span>) at org.apache.commons.httpclient.HttpConnection.flushRequestOutputStream(HttpConnection.java:<span class="number">828</span>) at org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:<span class="number">2116</span>) at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:<span class="number">1096</span>) at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:<span class="number">398</span>) at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:<span class="number">171</span>) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:<span class="number">397</span>) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:<span class="number">323</span>) ``` ```java Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:<span class="number">387</span>) at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:<span class="number">292</span>) at sun.security.validator.Validator.validate(Validator.java:<span class="number">260</span>) at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:<span class="number">324</span>) at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:<span class="number">229</span>) at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:<span class="number">124</span>) at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:<span class="number">1491</span>) ... <span class="number">19</span> more Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:<span class="number">141</span>) at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:<span class="number">126</span>) at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:<span class="number">280</span>) at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:<span class="number">382</span>) ... <span class="number">25</span> more</span><br></pre></td></tr></table></figure>

<p>solution</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">cd</span> <span class="variable">$&#123;JAVA_HOME&#125;</span>/jre/lib/security</span><br><span class="line"></span><br><span class="line">keytool -import -<span class="built_in">alias</span> codz -keystore cacerts -file <span class="variable">$&#123;JAVA_HOME&#125;</span>/jre/lib/security/codz.cer  </span><br><span class="line"></span><br><span class="line">keytool -list -keystore cacerts -<span class="built_in">alias</span> codz</span><br></pre></td></tr></table></figure>

<h2 id="Reference"><a href="#Reference" class="headerlink" title="Reference"></a>Reference</h2><ul>
<li><a href="http://blog.csdn.net/wangjunjun2008/article/details/37662851" target="_blank" rel="noopener">将安全证书导入到java的cacerts证书库</a></li>
</ul>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

        
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://codz-me.vercel.app/2016/08/12/nginx-tomcat-config-https/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/head.png">
      <meta itemprop="name" content="laudukang">
      <meta itemprop="description" content="Bug Not Found">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Code Is Poetry">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          
            <a href="/2016/08/12/nginx-tomcat-config-https/" class="post-title-link" itemprop="url">HTTPS 证书生成 & Nginx/Tomcat 配置 HTTPS</a>
        </h1>

        <div class="post-meta">
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2017-02-20 08:48:31 08:48:31" itemprop="dateModified" datetime="2017-02-20T08:48:31+08:00">2017-02-20 08:48:31</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Web/" itemprop="url" rel="index">
                    <span itemprop="name">Web</span>
                  </a>
                </span>
            </span>

          
            <span id="/2016/08/12/nginx-tomcat-config-https/" class="post-meta-item leancloud_visitors" data-flag-title="HTTPS 证书生成 & Nginx/Tomcat 配置 HTTPS" title="阅读次数">
                <span hidden class="leancloud-visitors-count"></span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <ol>
<li><p>OpenSSL安装</p>
<p>OpenSSL官网，或者参考 linux升级OpenSSL</p>
<p>中间可能会遇到 openssl.cnf 的问题，请使用 openssl-1.0.1t.tar.gz 包 apps下的 demoCA 和 openssl.cnf</p>
</li>
<li><p>证书生成</p>
<ul>
<li><p>单向认证，参考 Nginx单向认证的安装配置</p>
<figure class="highlight pgsql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">openssl genrsa -des3 -<span class="keyword">out</span> <span class="keyword">server</span>.key <span class="number">2048</span> #自定义密码</span><br><span class="line"></span><br><span class="line">openssl req -<span class="built_in">new</span> -key <span class="keyword">server</span>.key -<span class="keyword">out</span> <span class="keyword">server</span>.csr</span><br><span class="line"></span><br><span class="line">#<span class="comment">---------------------------------------------------------------------------------------------------------------</span></span><br><span class="line">Enter pass phrase <span class="keyword">for</span> <span class="keyword">server</span>.key: 自定义密码</span><br><span class="line">Country <span class="type">Name</span> (<span class="number">2</span> letter code) [XX]: CN                                           #国家</span><br><span class="line">State <span class="keyword">or</span> Province <span class="type">Name</span> (<span class="keyword">full</span> <span class="type">name</span>) []: GD                                       #区域或是省份</span><br><span class="line">Locality <span class="type">Name</span> (eg, city) [<span class="keyword">Default</span> City]: SZ                                     #地区局部名字</span><br><span class="line">Organization <span class="type">Name</span> (eg, company) [<span class="keyword">Default</span> Company Ltd]: Test                     #机构名称：填写公司名</span><br><span class="line">Organizational Unit <span class="type">Name</span> (eg, section) []: Test                                 #组织单位名称:部门名称</span><br><span class="line">Common <span class="type">Name</span> (eg, your <span class="type">name</span> <span class="keyword">or</span> your <span class="keyword">server</span><span class="string">'s hostname) []: *.domain.com          #网站域名</span></span><br><span class="line"><span class="string">Email Address []: admin@domain.com                                              #邮箱地址</span></span><br><span class="line"><span class="string">A challenge password []:                                                        #输入一个密码</span></span><br><span class="line"><span class="string">An optional company name []:                                                    #一个可选的公司名称</span></span><br><span class="line"><span class="string">#---------------------------------------------------------------------------------------------------------------</span></span><br></pre></td></tr></table></figure>

<blockquote><p>怎么让nginx配置SSL安全证书重启免输入密码，不然Nginx、Tomcat使用该私钥启动的时候需要输入上面的密钥</p>
<p>openssl rsa -in server.key -out server.key.unsecure<br>openssl x509 -req -days 365 -in server.csr -signkey server.key.unsecure -out server.crt  #使用上面的密钥和CSR对证书进行签名</p>
</blockquote>
</li>
<li><p>双向认证，参考 openssl生成SSL证书的流程</p>
<p>CA根证书的生成</p>
<figure class="highlight stata"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"># <span class="keyword">Generate</span> <span class="keyword">CA</span> private key   </span><br><span class="line">openssl genrsa -<span class="keyword">out</span> <span class="keyword">ca</span>.key 2048   </span><br><span class="line"># <span class="keyword">Generate</span> CSR   </span><br><span class="line">openssl req -new -key <span class="keyword">ca</span>.key -<span class="keyword">out</span> <span class="keyword">ca</span>.csr  </span><br><span class="line"># <span class="keyword">Generate</span> Self Signed certificate（<span class="keyword">CA</span> 根证书）  </span><br><span class="line">openssl x509 -req -days 365 -<span class="keyword">in</span> <span class="keyword">ca</span>.csr -signkey <span class="keyword">ca</span>.key -<span class="keyword">out</span> <span class="keyword">ca</span>.crt</span><br></pre></td></tr></table></figure>

<p>用户证书的生成</p>
<figure class="highlight axapta"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"># 服务器端用户证书</span></span><br><span class="line"><span class="meta"># private key  </span></span><br><span class="line">openssl genrsa -des3 -out <span class="keyword">server</span>.key <span class="number">1024</span>   </span><br><span class="line"><span class="meta"># generate csr  </span></span><br><span class="line">openssl req -<span class="keyword">new</span> -key <span class="keyword">server</span>.key -out <span class="keyword">server</span>.csr  </span><br><span class="line"><span class="meta"># generate certificate  </span></span><br><span class="line">openssl ca -in <span class="keyword">server</span>.csr -out <span class="keyword">server</span>.crt -cert ca.crt -keyfile ca.key  </span><br><span class="line"></span><br><span class="line"><span class="meta"># 客户端用户证书</span></span><br><span class="line">openssl genrsa -des3 -out <span class="keyword">client</span>.key <span class="number">1024</span>   </span><br><span class="line">openssl req -<span class="keyword">new</span> -key <span class="keyword">client</span>.key -out <span class="keyword">client</span>.csr  </span><br><span class="line">openssl ca -in <span class="keyword">client</span>.csr -out <span class="keyword">client</span>.crt -cert ca.crt -keyfile ca.key</span><br><span class="line">免密钥启动同上，TXT_DB error number <span class="number">2</span> 异常请参考 openssl TXT_DB error number <span class="number">2</span></span><br></pre></td></tr></table></figure>

<p>生成pem格式证书<br>有时需要用到pem格式的证书，可以用以下方式合并证书文件（crt）和私钥文件（key）来生成</p>
<figure class="highlight axapta"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$cat <span class="keyword">client</span>.crt <span class="keyword">client</span>.key&gt; <span class="keyword">client</span>.pem</span><br><span class="line">$cat <span class="keyword">server</span>.crt <span class="keyword">server</span>.key &gt; <span class="keyword">server</span>.pem</span><br></pre></td></tr></table></figure>
</li>
</ul>
</li>
<li><p>Nginx、Tomcat配置HTTPS</p>
<p>nginx.conf添加</p>
<figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="section">server</span> &#123;</span><br><span class="line">   <span class="attribute">listen</span>       <span class="number">443</span> ssl;</span><br><span class="line">   <span class="attribute">server_name</span>  localhost;</span><br><span class="line"></span><br><span class="line">   <span class="attribute">ssl_certificate</span>      /work/openssl/single/server.crt;</span><br><span class="line">   <span class="attribute">ssl_certificate_key</span>  /work/openssl/single/server.key.unsecure;</span><br><span class="line"></span><br><span class="line">   <span class="attribute">ssl_session_cache</span>    shared:SSL:<span class="number">1m</span>;</span><br><span class="line">   <span class="attribute">ssl_session_timeout</span>  <span class="number">5m</span>;</span><br><span class="line">   <span class="attribute">ssl_ciphers</span>  HIGH:!aNULL:!MD5;</span><br><span class="line">   <span class="attribute">ssl_prefer_server_ciphers</span>  <span class="literal">on</span>;</span><br><span class="line"></span><br><span class="line">   <span class="attribute">location</span> / &#123;</span><br><span class="line">            <span class="attribute">allow</span> all;</span><br><span class="line">            <span class="attribute">proxy_pass</span> https://192.168.1.121:443;</span><br><span class="line">            <span class="attribute">proxy_set_header</span> Host <span class="variable">$host</span>;</span><br><span class="line">            <span class="attribute">proxy_set_header</span> Upgrade <span class="variable">$http_upgrade</span>;</span><br><span class="line">            <span class="attribute">proxy_set_header</span> Connection <span class="string">"upgrade"</span>;</span><br><span class="line">            <span class="attribute">proxy_set_header</span> X-Real-Ip <span class="variable">$remote_addr</span>;</span><br><span class="line">            <span class="attribute">proxy_set_header</span> X-Forwarded-For <span class="variable">$proxy_add_x_forwarded_for</span>;</span><br><span class="line">            <span class="attribute">proxy_set_header</span> X-Forwarded-Proto <span class="variable">$scheme</span>;</span><br><span class="line">   &#125;</span><br></pre></td></tr></table></figure>

<p>tomcat server.xml添加</p>
<figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">&lt;Connector <span class="attribute">port</span>=<span class="string">"8443"</span> <span class="attribute">protocol</span>=<span class="string">"org.apache.coyote.http11.Http11AprProtocol"</span></span><br><span class="line">               <span class="attribute">maxThreads</span>=<span class="string">"150"</span> <span class="attribute">SSLEnabled</span>=<span class="string">"true"</span> <span class="attribute">scheme</span>=<span class="string">"https"</span> <span class="attribute">secure</span>=<span class="string">"true"</span></span><br><span class="line">               <span class="attribute">clientAuth</span>=<span class="string">"false"</span> <span class="attribute">SSLCertificateFile</span>=<span class="string">"/work/openssl/single/server.crt"</span> <span class="attribute">SSLProtocol</span>=<span class="string">"SSLv2+SSLv3+TLSv1"</span></span><br><span class="line">          <span class="attribute">SSLCertificateKeyFile</span>=<span class="string">"/work/openssl/single/server.key.unsecure"</span> <span class="attribute">SSLVerifyClient</span>=<span class="string">"optional"</span>/&gt;</span><br></pre></td></tr></table></figure>
<p>server.xml默认注释了</p>
<figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&lt;Connector <span class="attribute">port</span>=<span class="string">"8443"</span> <span class="attribute">protocol</span>=<span class="string">"org.apache.coyote.http11.Http11NioProtocol"</span></span><br><span class="line">               <span class="attribute">maxThreads</span>=<span class="string">"150"</span> <span class="attribute">SSLEnabled</span>=<span class="string">"true"</span> <span class="attribute">scheme</span>=<span class="string">"https"</span> <span class="attribute">secure</span>=<span class="string">"true"</span></span><br><span class="line">               <span class="attribute">clientAuth</span>=<span class="string">"false"</span> <span class="attribute">sslProtocol</span>=<span class="string">"TLS"</span> /&gt;</span><br></pre></td></tr></table></figure>
<p>需要注意protocol中的 Http11AprProtocol 与 Http11NioProtocol，加密算法不支持的话，可能报异常 <code>Java and SSL - java.security.NoSuchAlgorithmException</code></p>
</li>
<li><p>一个大坑</p>
<p>Ubuntu上跑Tengine，代理Windows上的应用，访问HTTPS页面时候总是报504错误，后来又报502错误。</p>
<p>排查了一个多小时后发现是Windows系统安装了Vmware Workstation，而Vmware的VMware Authorization Service自动启动了。</p>
<p>还有另外一个Vmware的服务忘记了，这两个服务会影响本地应用使用HTTPS，所以停止掉或禁用掉就可以了。</p>
<p><a href="http://tool.chinaz.com/pagestatus/" target="_blank" rel="noopener">HTTP状态码</a></p>
<blockquote><p>502 作为网关或者代理工作的服务器尝试执行请求时，从上游服务器接收到无效的响应。</p>
<p>504 作为网关或者代理工作的服务器尝试执行请求时，未能及时从上游服务器（URI标识出的服务器，例如HTTP、FTP、LDAP）或者辅助服务器（例如DNS）收到响应。 　　注意：某些代理服务器在DNS查询超时时会返回400或者500错误</p>
</blockquote>

</li>
</ol>
<p>参考资料：</p>
<ul>
<li><a href="http://my.oschina.net/itblog/blog/651434" target="_blank" rel="noopener">OpenSSL生成根证书CA及签发子证书</a></li>
<li><a href="http://my.oschina.net/u/658145/blog/75093" target="_blank" rel="noopener">Windows下Tomcat+nginx配置证书实现登录页https访问</a></li>
<li><a href="http://itindex.net/detail/50701-tomcat-bio-nio.apr" target="_blank" rel="noopener">Tomcat 的三种(bio,nio.apr) 高级 Connector 运行模式</a></li>
<li><a href="http://blog.csdn.net/na_tion/article/details/17334669" target="_blank" rel="noopener">Nginx部署部分https与部分http</a></li>
<li><a href="https://iyaozhen.com/nginx-https-conf.html" target="_blank" rel="noopener">Nginx HTTPS 配置实践</a></li>
</ul>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

        
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://codz-me.vercel.app/2016/07/28/ubuntu-desktop-boot-to-char-interface/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/head.png">
      <meta itemprop="name" content="laudukang">
      <meta itemprop="description" content="Bug Not Found">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Code Is Poetry">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          
            <a href="/2016/07/28/ubuntu-desktop-boot-to-char-interface/" class="post-title-link" itemprop="url">Ubuntu Desktop 16.04 设置默认启动到字符界面</a>
        </h1>

        <div class="post-meta">
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2016-07-28 22:48:51 22:48:51" itemprop="dateModified" datetime="2016-07-28T22:48:51+08:00">2016-07-28 22:48:51</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Linux/" itemprop="url" rel="index">
                    <span itemprop="name">Linux</span>
                  </a>
                </span>
            </span>

          
            <span id="/2016/07/28/ubuntu-desktop-boot-to-char-interface/" class="post-meta-item leancloud_visitors" data-flag-title="Ubuntu Desktop 16.04 设置默认启动到字符界面" title="阅读次数">
                <span hidden class="leancloud-visitors-count"></span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>检查目前状态</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ ls -l /lib/systemd/system/default.target</span><br><span class="line">lrwxrwxrwx 1 root root 16 May 12 16:05 /lib/systemd/system/default.target -&gt; graphical.target</span><br></pre></td></tr></table></figure>

<p>设置为默认启动字符界面</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl <span class="built_in">set</span>-default multi-user.target</span><br></pre></td></tr></table></figure>

<p>返回默认启动图形界面</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl <span class="built_in">set</span>-default graphical.target</span><br></pre></td></tr></table></figure>

<p>其他方法，例如，均失败告终</p>
<figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#1</span></span><br><span class="line"><span class="attr">sudo</span> <span class="string">vi /etc/default/grub</span></span><br><span class="line"></span><br><span class="line"><span class="attr">GRUB_CMDLINE_LINUX_DEFAULT</span>=<span class="string">"text"</span></span><br><span class="line"></span><br><span class="line"><span class="attr">sudo</span> <span class="string">update-grub2</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#2</span></span><br><span class="line"><span class="attr">sudo</span> <span class="string">vi /etc/init/rc-sysinit.conf</span></span><br><span class="line"></span><br><span class="line"><span class="attr">env</span> <span class="string">DEFAULT_RUNLEVEL=3</span></span><br></pre></td></tr></table></figure>

<h2 id="Reference"><a href="#Reference" class="headerlink" title="Reference"></a>Reference</h2><ul>
<li><p><a href="https://www.ubuntu.org.cn/viewtopic.php?f=49&amp;t=478193" target="_blank" rel="noopener">https://www.ubuntu.org.cn/viewtopic.php?f=49&amp;t=478193</a></p>
</li>
<li><p><a href="http://www.2cto.com/os/201308/237632.html" target="_blank" rel="noopener">http://www.2cto.com/os/201308/237632.html</a></p>
</li>
</ul>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

        
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://codz-me.vercel.app/2016/07/21/ngrok-compile-and-run-online/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/head.png">
      <meta itemprop="name" content="laudukang">
      <meta itemprop="description" content="Bug Not Found">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Code Is Poetry">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          
            <a href="/2016/07/21/ngrok-compile-and-run-online/" class="post-title-link" itemprop="url">从编译到使用 - ngrok 服务搭建</a>
        </h1>

        <div class="post-meta">
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2017-02-20 08:42:32 08:42:32" itemprop="dateModified" datetime="2017-02-20T08:42:32+08:00">2017-02-20 08:42:32</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Linux/" itemprop="url" rel="index">
                    <span itemprop="name">Linux</span>
                  </a>
                </span>
            </span>

          
            <span id="/2016/07/21/ngrok-compile-and-run-online/" class="post-meta-item leancloud_visitors" data-flag-title="从编译到使用 - ngrok 服务搭建" title="阅读次数">
                <span hidden class="leancloud-visitors-count"></span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h2 id="背景"><a href="#背景" class="headerlink" title="背景"></a>背景</h2><p><a href="https://ngrok.com/" target="_blank" rel="noopener">ngrok官网</a>被q，而且访问速度慢，最主要的是不支持域名绑定，每次启动都是随机的二级域名，333</p>
<p><a href="https://www.ngrok.cc/" target="_blank" rel="noopener">ngrok.cc-Sunny-Ngrok内网转发</a>，服务器在香港，访问速度也慢，支持自定义系统域名，但只能定义一个（可以先定义TCP端口转发，保存后编辑，可以修改成系统分配域名，这样子就可以有多个自定义的系统域名，然并卵，客户端连接不上，一直提示该域名已被注册，官方做限制了吧）。</p>
<p>对比了上面两个服务，加上自己的需求：</p>
<ul>
<li>需要多个自定义的域名；</li>
<li>尽量提升访问速度；决定自己搭建一个ngrok服务。</li>
</ul>
<p>搭建ngrok服务需要的资源：</p>
<ul>
<li>一个域名，需要定义泛解析；</li>
<li>一台ECS，需要公网IP</li>
</ul>
<p>以下操作建议在Ubuntu上尝试，不建议在Windows上尝试（花了一个晚上搞都没搞成功，第二天早上花一个小时在Ubuntu上完美运行）</p>
<h2 id="拉取ngrok源码"><a href="#拉取ngrok源码" class="headerlink" title="拉取ngrok源码"></a>拉取ngrok源码</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git <span class="built_in">clone</span> git@github.com:inconshreveable/ngrok.git /work/ngrok</span><br></pre></td></tr></table></figure>

<p>使用ngrok.com官方服务时，我们使用的是官方的SSL证书。</p>
<p>自建ngrokd服务，如果不想买SSL证书，我们需要生成自己的自签名证书，并编译一个携带该证书的ngrok客户端。</p>
<p>证书生成过程需要一个<code>NGROK_BASE_DOMAIN</code>。</p>
<p>以ngrok官方随机生成的地址693c358d.ngrok.com为例，其<code>NGROK_BASE_DOMAIN</code>就是<code>ngrok.com</code>，如果你要提供服务的地址为<code>example.ngrok.xxx.com</code>，那<code>NGROK_BASE_DOMAIN</code>就应该是<code>ngrok.xxx.com</code>。</p>
<p>这里以<code>NGROK_BASE_DOMAIN=&quot;codz.me&quot;</code>为例，生成证书的命令如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">cd</span> /work/ngrok</span><br><span class="line">openssl genrsa -out rootCA.key 2048</span><br><span class="line">openssl req -x509 -new -nodes -key rootCA.key -subj <span class="string">"/CN=codz.me"</span> -days 5000 -out rootCA.pem</span><br><span class="line">openssl genrsa -out device.key 2048</span><br><span class="line">openssl req -new -key device.key -subj <span class="string">"/CN=codz.me"</span> -out device.csr</span><br><span class="line">openssl x509 -req -<span class="keyword">in</span> device.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out device.crt -days 5000</span><br></pre></td></tr></table></figure>

<p>ngrok目录下新建了如下文件</p>
<figure class="highlight angelscript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">-rw-r--r-- <span class="number">1</span> root root  <span class="number">985</span> Jul <span class="number">21</span> <span class="number">08</span>:<span class="number">52</span> device.crt</span><br><span class="line">-rw-r--r-- <span class="number">1</span> root root  <span class="number">895</span> Jul <span class="number">21</span> <span class="number">08</span>:<span class="number">52</span> device.csr</span><br><span class="line">-rw-r--r-- <span class="number">1</span> root root <span class="number">1679</span> Jul <span class="number">21</span> <span class="number">08</span>:<span class="number">52</span> device.key</span><br><span class="line">-rw-r--r-- <span class="number">1</span> root root <span class="number">1675</span> Jul <span class="number">21</span> <span class="number">08</span>:<span class="number">51</span> rootCA.key</span><br><span class="line">-rw-r--r-- <span class="number">1</span> root root <span class="number">1103</span> Jul <span class="number">21</span> <span class="number">08</span>:<span class="number">52</span> rootCA.pem</span><br><span class="line">-rw-r--r-- <span class="number">1</span> root root   <span class="number">17</span> Jul <span class="number">21</span> <span class="number">08</span>:<span class="number">52</span> rootCA.srl</span><br></pre></td></tr></table></figure>

<p>ngrok通过bindata将ngrok源码目录下的assets目录打包到可执行文件(ngrokd和ngrok)中去，<code>assets/client/tls和assets/server/tls</code>下分别存放着用于ngrok和ngrokd的默认证书文件。</p>
<p>我们需要将它们替换成我们自己生成的，因此这一步务必放在编译可执行文件之前。</p>
<p>所以，执行下面拷贝命令：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">cp rootCA.pem assets/client/tls/ngrokroot.crt</span><br><span class="line">cp device.crt assets/server/tls/snakeoil.crt</span><br><span class="line">cp device.key assets/server/tls/snakeoil.key</span><br></pre></td></tr></table></figure>

<h2 id="搭建go环境"><a href="#搭建go环境" class="headerlink" title="搭建go环境"></a>搭建go环境</h2><p><a href="https://golang.org/" target="_blank" rel="noopener">Golang官网</a>被q，下载安装包特么慢，<a href="https://golangtc.com/download" target="_blank" rel="noopener">Golang中国</a>提供下载站点，我使用的是1.6.3版本；</p>
<p>下载并解压到go的默认安装路径<code>/usr/local/go</code></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">cd</span> /work/download</span><br><span class="line">wget http://www.golangtc.com/static/go/1.6.3/go1.6.3.linux-amd64.tar.gz</span><br><span class="line">tar -zxvf go1.6.3.linux-amd64.tar.gz -C /usr/<span class="built_in">local</span></span><br></pre></td></tr></table></figure>

<p>修改PATH</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">vi /etc/profile</span><br><span class="line"><span class="built_in">export</span> GOROOT=/usr/<span class="built_in">local</span>/go</span><br><span class="line"><span class="built_in">export</span> PATH=<span class="variable">$PATH</span>:<span class="variable">$GOROOT</span>/bin</span><br><span class="line"><span class="built_in">source</span> /etc/profile</span><br></pre></td></tr></table></figure>
<p>正确配置后，go env可以查看得到当前go的环境</p>
<figure class="highlight ini"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">GOARCH</span>=<span class="string">"amd64"</span></span><br><span class="line"><span class="attr">GOBIN</span>=<span class="string">""</span></span><br><span class="line"><span class="attr">GOEXE</span>=<span class="string">""</span></span><br><span class="line"><span class="attr">GOHOSTARCH</span>=<span class="string">"amd64"</span></span><br><span class="line"><span class="attr">GOHOSTOS</span>=<span class="string">"linux"</span></span><br><span class="line"><span class="attr">GOOS</span>=<span class="string">"linux"</span></span><br><span class="line"><span class="attr">GOPATH</span>=<span class="string">""</span></span><br><span class="line"><span class="attr">GORACE</span>=<span class="string">""</span></span><br><span class="line"><span class="attr">GOROOT</span>=<span class="string">"/usr/local/go"</span></span><br><span class="line"><span class="attr">GOTOOLDIR</span>=<span class="string">"/usr/local/go/pkg/tool/linux_amd64"</span></span><br><span class="line"><span class="attr">GO15VENDOREXPERIMENT</span>=<span class="string">"1"</span></span><br><span class="line"><span class="attr">CC</span>=<span class="string">"gcc"</span></span><br><span class="line"><span class="attr">GOGCCFLAGS</span>=<span class="string">"-fPIC -m64 -pthread -fmessage-length=0"</span></span><br><span class="line"><span class="attr">CXX</span>=<span class="string">"g++"</span></span><br><span class="line"><span class="attr">CGO_ENABLED</span>=<span class="string">"1"</span></span><br></pre></td></tr></table></figure>

<h2 id="编译安装"><a href="#编译安装" class="headerlink" title="编译安装"></a>编译安装</h2><p>进入<code>/work/ngrok</code>目录</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">make release-server release-client</span><br></pre></td></tr></table></figure>

<p>正常的话，<code>ngrok/bin</code>目录下应该有<code>ngrokd</code>和<code>ngrok</code>两个可执行文件，前面一个是服务端的，后面一个是客户端的；</p>
<p>需要Windows下的<code>ngrok.exe</code>可以通过下面命令构建，正常的话<code>ngrok/bin/windows_amd64</code>下会生成的<code>ngrok.exe</code>文件；</p>
<figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">GOOS</span>=windows <span class="attribute">GOARCH</span>=amd64 make release-client</span><br></pre></td></tr></table></figure>

<p>编译mac客户端（没实际操作）</p>
<figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">GOOS</span>=darwin <span class="attribute">GOARCH</span>=amd64 make release-client</span><br></pre></td></tr></table></figure>

<p>make很可能出现的错误有（来自Windows下的错误信息，Ubuntu下跑一切正常）</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">package archive/zip: unrecognized import path "archive/zip" (import path does not <span class="keyword">begin</span> <span class="keyword">with</span> hostname)</span><br><span class="line"><span class="keyword">package</span> <span class="keyword">bytes</span>: unrecognized <span class="keyword">import</span> <span class="keyword">path</span> <span class="string">"bytes"</span> (<span class="keyword">import</span> <span class="keyword">path</span> does <span class="keyword">not</span> <span class="keyword">begin</span> <span class="keyword">with</span> hostname)</span><br><span class="line"><span class="keyword">package</span> <span class="keyword">encoding</span>/<span class="keyword">json</span>: unrecognized <span class="keyword">import</span> <span class="keyword">path</span> <span class="string">"encoding/json"</span> (<span class="keyword">import</span> <span class="keyword">path</span> does <span class="keyword">not</span> <span class="keyword">begin</span> <span class="keyword">with</span> hostname)</span><br><span class="line"><span class="keyword">package</span> <span class="keyword">encoding</span>/<span class="keyword">xml</span>: unrecognized <span class="keyword">import</span> <span class="keyword">path</span> <span class="string">"encoding/xml"</span> (<span class="keyword">import</span> <span class="keyword">path</span> does <span class="keyword">not</span> <span class="keyword">begin</span> <span class="keyword">with</span> hostname)</span><br><span class="line"><span class="keyword">package</span> <span class="keyword">errors</span>: unrecognized <span class="keyword">import</span> <span class="keyword">path</span> <span class="string">"errors"</span> (<span class="keyword">import</span> <span class="keyword">path</span> does <span class="keyword">not</span> <span class="keyword">begin</span> <span class="keyword">with</span> hostname)</span><br><span class="line"><span class="keyword">package</span> expvar: unrecognized <span class="keyword">import</span> <span class="keyword">path</span> <span class="string">"expvar"</span> (<span class="keyword">import</span> <span class="keyword">path</span> does <span class="keyword">not</span> <span class="keyword">begin</span> <span class="keyword">with</span> hostname)</span><br><span class="line"><span class="keyword">package</span> flag: unrecognized <span class="keyword">import</span> <span class="keyword">path</span> <span class="string">"flag"</span> (<span class="keyword">import</span> <span class="keyword">path</span> does <span class="keyword">not</span> <span class="keyword">begin</span> <span class="keyword">with</span> hostname)</span><br><span class="line"><span class="keyword">package</span> fmt: unrecognized <span class="keyword">import</span> <span class="keyword">path</span> <span class="string">"fmt"</span> (<span class="keyword">import</span> <span class="keyword">path</span> does <span class="keyword">not</span> <span class="keyword">begin</span> <span class="keyword">with</span> hostname)</span><br></pre></td></tr></table></figure>

<h2 id="启动ngrok"><a href="#启动ngrok" class="headerlink" title="启动ngrok"></a>启动ngrok</h2><h3 id="服务端启动"><a href="#服务端启动" class="headerlink" title="服务端启动"></a>服务端启动</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">cd</span> /work/ngrok/bin</span><br><span class="line">ngrokd -domain=<span class="string">"codz.me"</span> -httpAddr=<span class="string">":8088"</span> -httpsAddr=<span class="string">":8089"</span></span><br></pre></td></tr></table></figure>
<p>-domain的内容需要与上面生成证书所填的<code>NGROK_BASE_DOMAIN</code>一致；</p>
<p>自定义http、https提供服务的端口，据此你使用的二级域名应该是 http://[自定义].codz.me:8088</p>
<p>其他有用的启动脚本</p>
<ul>
<li><p>后台启动，输出日志</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">nohup ngrokd -domain=<span class="string">"codz.me"</span> -httpAddr=<span class="string">":8088"</span> -httpsAddr=<span class="string">":8089"</span> &gt;/tmp/ngrok.log 2&gt;&amp;1 &amp;</span><br></pre></td></tr></table></figure>
</li>
<li><p>后台启动不输出日志</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">nohup ngrokd -domain=<span class="string">"codz.me"</span> -httpAddr=<span class="string">":8088"</span> -httpsAddr=<span class="string">":8089"</span> &gt;/dev/null 2&gt;&amp;1 &amp;</span><br></pre></td></tr></table></figure>

</li>
</ul>
<h3 id="客户端启动"><a href="#客户端启动" class="headerlink" title="客户端启动"></a>客户端启动</h3><p>拷贝编译好的ngrok客户端可执行文件到需要的机子上，给予执行权限，创建配置文件<code>ngrok.cfg</code>：</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">server_addr:</span> <span class="string">"codz.me:4443"</span></span><br><span class="line"><span class="attr">trust_host_root_certs:</span> <span class="literal">false</span></span><br><span class="line"></span><br><span class="line"><span class="attr">tunnels:</span></span><br><span class="line">  <span class="attr">www:</span></span><br><span class="line">   <span class="attr">subdomain:</span> <span class="string">"test"</span></span><br><span class="line">   <span class="attr">proto:</span></span><br><span class="line">    <span class="attr">http:</span> <span class="number">192.168</span><span class="number">.1</span><span class="number">.121</span><span class="string">:8000</span></span><br></pre></td></tr></table></figure>

<p>其中，<code>server_addr</code>需要跟<code>NGROK_BASE_DOMAIN</code>填写一致，否则服务端会报证书错误；</p>
<p><code>trust_host_root_certs</code>需要设置为false；</p>
<p><code>trust_host_root_certs</code>参数指示建立TLS连接到服务器时ngrok信任的根证书在计算机上。默认情况下，ngrok只信任的ngrok.com根证书；</p>
<p><code>trust_host_root_certs</code>，对于ngrok官方server一般为<code>true</code>，现在官网国内不能用，通常为自编译的，有自己的证书，所以要设为<code>false</code>。</p>
<p>启动客户端ngrok，之后就可以使用<code>http://test.codz.me:8088</code>来访问本地<code>192.168.121:8000</code>的资源了</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">./ngrok -config ngrok.cfg start www</span><br></pre></td></tr></table></figure>

<p>配置文件写法，来自ngrok.cc</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">server_addr:</span> <span class="string">"server.ngrok.cc:4443"</span></span><br><span class="line"><span class="attr">auth_token:</span> <span class="string">""</span> <span class="comment">#授权token，在www.ngrok.cc平台注册账号获取</span></span><br><span class="line"><span class="attr">tunnels:</span></span><br><span class="line">  <span class="attr">sunny:</span></span><br><span class="line">   <span class="attr">subdomain:</span> <span class="string">"sunny"</span> <span class="comment">#定义服务器分配域名前缀，跟平台上的要一样</span></span><br><span class="line">   <span class="attr">proto:</span></span><br><span class="line">    <span class="attr">http:</span> <span class="number">80</span> <span class="comment">#映射端口，不加ip默认本机</span></span><br><span class="line">    <span class="attr">https:</span> <span class="number">80</span></span><br><span class="line">  <span class="attr">web:</span></span><br><span class="line">   <span class="attr">subdomain:</span> <span class="string">"web"</span> <span class="comment">#定义服务器分配域名前缀</span></span><br><span class="line">   <span class="attr">proto:</span></span><br><span class="line">    <span class="attr">http:</span> <span class="number">192.168</span><span class="number">.1</span><span class="number">.100</span><span class="string">:80</span> <span class="comment">#映射端口，可以通过加ip为内网任意一台映射</span></span><br><span class="line">    <span class="attr">https:</span> <span class="number">192.168</span><span class="number">.1</span><span class="number">.100</span><span class="string">:80</span></span><br><span class="line">  <span class="attr">web1:</span></span><br><span class="line">    <span class="attr">hostname:</span> <span class="string">"www.sunnyos.com"</span></span><br><span class="line">    <span class="attr">proto:</span></span><br><span class="line">      <span class="attr">http:</span> <span class="number">80</span></span><br><span class="line">  <span class="attr">web2:</span></span><br><span class="line">    <span class="attr">hostname:</span> <span class="string">"sunnyos.com"</span></span><br><span class="line">    <span class="attr">proto:</span></span><br><span class="line">      <span class="attr">http:</span> <span class="number">80</span>  </span><br><span class="line">  <span class="attr">ssh:</span></span><br><span class="line">   <span class="attr">remote_port:</span> <span class="number">50001</span> <span class="comment">#服务器分配tcp转发端口，如果不填写此项则又服务器分配</span></span><br><span class="line">   <span class="attr">proto:</span></span><br><span class="line">    <span class="attr">tcp:</span> <span class="number">22</span> <span class="comment">#映射本地的22端口</span></span><br><span class="line">  <span class="attr">ssh1:</span> <span class="comment">#将由服务器分配端口</span></span><br><span class="line">    <span class="attr">proto:</span></span><br><span class="line">      <span class="attr">tcp:</span> <span class="number">21</span></span><br></pre></td></tr></table></figure>


<p>至此，all done.</p>
<p>实测，单个用户通过ngrok访问内网速度有所提升；</p>
<p>多个用户同时访问效果不是很明显，可能与ECS带宽有关（→_→ 1Mbps），ngrok使用多个自定义域名目的已达成，这是重点。</p>
<p>参考：</p>
<ul>
<li><a href="https://aotu.io/notes/2016/02/19/ngrok/" target="_blank" rel="noopener">https://aotu.io/notes/2016/02/19/ngrok/</a></li>
<li><a href="http://tonybai.com/2015/03/14/selfhost-ngrok-service" target="_blank" rel="noopener">http://tonybai.com/2015/03/14/selfhost-ngrok-service</a></li>
<li><a href="http://blog.csdn.net/tao_627/article/details/17191977" target="_blank" rel="noopener">http://blog.csdn.net/tao_627/article/details/17191977</a></li>
<li><a href="http://briteming.blogspot.com/2016/04/ngrok.html" target="_blank" rel="noopener">http://briteming.blogspot.com/2016/04/ngrok.html</a></li>
</ul>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

        
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://codz-me.vercel.app/2016/05/30/elasticsearch-note-2/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/head.png">
      <meta itemprop="name" content="laudukang">
      <meta itemprop="description" content="Bug Not Found">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Code Is Poetry">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          
            <a href="/2016/05/30/elasticsearch-note-2/" class="post-title-link" itemprop="url">（二）Elasticsearch学习笔记：CURD</a>
        </h1>

        <div class="post-meta">
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2017-02-22 22:16:59 22:16:59" itemprop="dateModified" datetime="2017-02-22T22:16:59+08:00">2017-02-22 22:16:59</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Elasticsearch/" itemprop="url" rel="index">
                    <span itemprop="name">Elasticsearch</span>
                  </a>
                </span>
            </span>

          
            <span id="/2016/05/30/elasticsearch-note-2/" class="post-meta-item leancloud_visitors" data-flag-title="（二）Elasticsearch学习笔记：CURD" title="阅读次数">
                <span hidden class="leancloud-visitors-count"></span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h2 id="Create"><a href="#Create" class="headerlink" title="Create"></a>Create</h2><p>PUT <code>http://192.168.56.101:9200/school/student/1</code>，自动创建school索引，学生类型，最后指定id为1</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">    <span class="attr">"name"</span>:<span class="string">"许薇"</span>,</span><br><span class="line">    <span class="attr">"class"</span>:<span class="string">"计算机科学与技术1班"</span>,</span><br><span class="line">    <span class="attr">"sc_id"</span>:<span class="string">"001"</span>,</span><br><span class="line">    <span class="attr">"from"</span>:<span class="string">"广州"</span>,</span><br><span class="line">    <span class="attr">"birth"</span>:<span class="string">"1993-1-1"</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>成功添加后返回下面JSON内容</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="attr">"_index"</span>: <span class="string">"school"</span>,</span><br><span class="line">  <span class="attr">"_type"</span>: <span class="string">"student"</span>,</span><br><span class="line">  <span class="attr">"_id"</span>: <span class="string">"1"</span>,</span><br><span class="line">  <span class="attr">"_version"</span>: <span class="number">1</span>,</span><br><span class="line">  <span class="attr">"_shards"</span>: &#123;</span><br><span class="line">    <span class="attr">"total"</span>: <span class="number">2</span>,</span><br><span class="line">    <span class="attr">"successful"</span>: <span class="number">1</span>,</span><br><span class="line">    <span class="attr">"failed"</span>: <span class="number">0</span></span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="attr">"created"</span>: <span class="literal">true</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="Update"><a href="#Update" class="headerlink" title="Update"></a>Update</h2><p>POST <code>http://192.168.56.101:9200/school/student/1/_update</code>，发送要更新的字段，例如</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">   <span class="attr">"script"</span>:<span class="string">"ctx._source.from=\"深圳\""</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>更新成功后，<code>_version</code>字段会+1</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="attr">"_index"</span>: <span class="string">"school"</span>,</span><br><span class="line">  <span class="attr">"_type"</span>: <span class="string">"student"</span>,</span><br><span class="line">  <span class="attr">"_id"</span>: <span class="string">"1"</span>,</span><br><span class="line">  <span class="attr">"_version"</span>: <span class="number">4</span>,</span><br><span class="line">  <span class="attr">"_shards"</span>: &#123;</span><br><span class="line">    <span class="attr">"total"</span>: <span class="number">2</span>,</span><br><span class="line">    <span class="attr">"successful"</span>: <span class="number">1</span>,</span><br><span class="line">    <span class="attr">"failed"</span>: <span class="number">0</span></span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>再次查询，可以看到<code>from</code>字段是更新了的</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="attr">"_index"</span>: <span class="string">"school"</span>,</span><br><span class="line">  <span class="attr">"_type"</span>: <span class="string">"student"</span>,</span><br><span class="line">  <span class="attr">"_id"</span>: <span class="string">"1"</span>,</span><br><span class="line">  <span class="attr">"_version"</span>: <span class="number">4</span>,</span><br><span class="line">  <span class="attr">"found"</span>: <span class="literal">true</span>,</span><br><span class="line">  <span class="attr">"_source"</span>: &#123;</span><br><span class="line">    <span class="attr">"name"</span>: <span class="string">"许薇"</span>,</span><br><span class="line">    <span class="attr">"class"</span>: <span class="string">"计算机科学与技术1班"</span>,</span><br><span class="line">    <span class="attr">"sc_id"</span>: <span class="string">"001"</span>,</span><br><span class="line">    <span class="attr">"from"</span>: <span class="string">"深圳"</span>,</span><br><span class="line">    <span class="attr">"birth"</span>: <span class="string">"1993-1-1"</span></span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="Read"><a href="#Read" class="headerlink" title="Read"></a>Read</h2><p>GET <code>http://192.168.56.101:9200/school/student/1</code>，成功查询到则返回下面JSON数据：</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="attr">"_index"</span>: <span class="string">"school"</span>,</span><br><span class="line">  <span class="attr">"_type"</span>: <span class="string">"student"</span>,</span><br><span class="line">  <span class="attr">"_id"</span>: <span class="string">"1"</span>,</span><br><span class="line">  <span class="attr">"_version"</span>: <span class="number">1</span>,</span><br><span class="line">  <span class="attr">"found"</span>: <span class="literal">true</span>,</span><br><span class="line">  <span class="attr">"_source"</span>: &#123;</span><br><span class="line">    <span class="attr">"name"</span>: <span class="string">"许薇"</span>,</span><br><span class="line">    <span class="attr">"class"</span>: <span class="string">"计算机科学与技术1班"</span>,</span><br><span class="line">    <span class="attr">"sc_id"</span>: <span class="string">"001"</span>,</span><br><span class="line">    <span class="attr">"from"</span>: <span class="string">"深圳"</span>,</span><br><span class="line">    <span class="attr">"birth"</span>: <span class="string">"1993-1-1"</span></span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="Delete"><a href="#Delete" class="headerlink" title="Delete"></a>Delete</h2><p>DELETE <code>http://192.168.56.101:9200/school/student/2</code>，</p>
<p>成功删除后返回下面JSON信息，其中<code>_version</code>也会+1；</p>
<p>文档删除后，ES保留了删除文档的版本信息，所以仍然可以检查该版本号。</p>
<p>默认情况下，版本信息在删除的60秒内可用，可以通过<code>index.gc_deletes</code>修改可用时间。</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="attr">"found"</span>: <span class="literal">true</span>,</span><br><span class="line">  <span class="attr">"_index"</span>: <span class="string">"school"</span>,</span><br><span class="line">  <span class="attr">"_type"</span>: <span class="string">"student"</span>,</span><br><span class="line">  <span class="attr">"_id"</span>: <span class="string">"2"</span>,</span><br><span class="line">  <span class="attr">"_version"</span>: <span class="number">2</span>,</span><br><span class="line">  <span class="attr">"_shards"</span>: &#123;</span><br><span class="line">    <span class="attr">"total"</span>: <span class="number">2</span>,</span><br><span class="line">    <span class="attr">"successful"</span>: <span class="number">1</span>,</span><br><span class="line">    <span class="attr">"failed"</span>: <span class="number">0</span></span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

        
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://codz-me.vercel.app/2016/05/29/elasticsearch-note-1/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/head.png">
      <meta itemprop="name" content="laudukang">
      <meta itemprop="description" content="Bug Not Found">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Code Is Poetry">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          
            <a href="/2016/05/29/elasticsearch-note-1/" class="post-title-link" itemprop="url">（一）Elasticsearch学习笔记：安装与配置</a>
        </h1>

        <div class="post-meta">
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2017-03-10 21:14:17 21:14:17" itemprop="dateModified" datetime="2017-03-10T21:14:17+08:00">2017-03-10 21:14:17</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Elasticsearch/" itemprop="url" rel="index">
                    <span itemprop="name">Elasticsearch</span>
                  </a>
                </span>
            </span>

          
            <span id="/2016/05/29/elasticsearch-note-1/" class="post-meta-item leancloud_visitors" data-flag-title="（一）Elasticsearch学习笔记：安装与配置" title="阅读次数">
                <span hidden class="leancloud-visitors-count"></span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h2 id="Elasticsearch-简介"><a href="#Elasticsearch-简介" class="headerlink" title="Elasticsearch 简介"></a>Elasticsearch 简介</h2><p><code>ElasticSearch</code>（简称 ES） 是一个基于 Lucene 构建的开源，分布式，RESTful 搜索引擎。</p>
<p>设计用于云计算中，能够达到搜索实时、稳定、可靠和快速，并且安装使用方便。</p>
<p>支持通过 HTTP 请求，使用 JSON 进行数据索引。另外，ES还有非常强大的统计功能 (facets) , 一个例子：现在系统中的需要实时处理的统计功能从 MySQL 转接到 ElasticSearch , 准确性一致, 速度从原来 1900ms -&gt; 50ms。</p>
<p><code>Apache Lucene</code>只是一个库。</p>
<p>想要使用它，你必须使用Java来作为开发语言并将其直接集成到你的应用中，更糟糕的是，Lucene非常复杂，你需要深入了解检索的相关知识来理解它是如何工作的。</p>
<p><code>Elasticsearch</code>也使用Java开发并使用<code>Lucene</code>作为其核心来实现所有索引和搜索的功能，但是它的目的是通过简单的RESTful API来隐藏Lucene的复杂性，从而让全文搜索变得简单。</p>
<p>关系数据库与ES</p>
<blockquote><p>Relational DB -&gt; Databases -&gt; Tables -&gt; Rows -&gt; Columns<br>Elasticsearch -&gt; Indices -&gt; Types -&gt; Documents -&gt; Fields</p>
</blockquote>

<h2 id="Elasticsearch-安装"><a href="#Elasticsearch-安装" class="headerlink" title="Elasticsearch 安装"></a>Elasticsearch 安装</h2><ol>
<li><p>安装JDK<br>需要JDK1.7或以上，官方推荐使用最新版JDK</p>
</li>
<li><p>安装与启动ES<br>下载ES</p>
<figure class="highlight awk"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">https:<span class="regexp">//</span>download.elastic.co<span class="regexp">/elasticsearch/</span>release<span class="regexp">/org/</span>elasticsearch<span class="regexp">/distribution/</span>tar<span class="regexp">/elasticsearch/</span><span class="number">2.3</span>.<span class="number">3</span><span class="regexp">/elasticsearch-2.3.3.tar.gz</span></span><br></pre></td></tr></table></figure>
<p>解压到指定目录</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">tar -zxvf elasticsearch-2.3.3.tar.gz</span><br></pre></td></tr></table></figure>
<p>进入<code>bin</code>目录启动ES</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">cd</span> elasticsearch-2.3.3/bin</span><br><span class="line">./elasticsearch</span><br></pre></td></tr></table></figure>
<img src="/2016/05/29/elasticsearch-note-1/es-start.png" alt="start" title="start">

<p>至此，可以查看ES集群的信息</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">curl -XGET <span class="string">'http://localhost:9200?pretty'</span></span><br></pre></td></tr></table></figure>
<img src="/2016/05/29/elasticsearch-note-1/es-info.png" alt="info" title="info">
</li>
<li><p>关闭ES</p>
<p>三种方式关闭：</p>
<ul>
<li><p>如果节点是连接到控制台，按下Ctrl+C；</p>
</li>
<li><p>通过发送TERM信号杀掉服务器进程（参考Linux上的kill命令和Windows上的任务管理器）；</p>
</li>
<li><p>使用REST API</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">//关掉整个集群</span><br><span class="line">curl -XPOST http://localhost:9200/_cluster/nodes/_shutdown</span><br><span class="line"></span><br><span class="line">//关闭单一节点，假如节点标识符是BlrmMvBdSKiCeYGsiHijdg，如何查看见下一条</span><br><span class="line">curl –XPOST http://localhost:9200/_cluster/nodes/BlrmMvBdSKiCeYGsiHijdg/_shutdown</span><br><span class="line"></span><br><span class="line">//查看节点标识符</span><br><span class="line">curl -XGET http://localhost:9200/_cluster/nodes/</span><br><span class="line"></span><br><span class="line">//检查集群健康度</span><br><span class="line">curl -XGET http://localhost:9200/_cluster/health?pretty</span><br></pre></td></tr></table></figure>

<img src="/2016/05/29/elasticsearch-note-1/es-health.png" alt="health" title="health">

</li>
</ul>
</li>
</ol>
<h2 id="Elasticsearch-插件"><a href="#Elasticsearch-插件" class="headerlink" title="Elasticsearch 插件"></a>Elasticsearch 插件</h2><h3 id="Marvel"><a href="#Marvel" class="headerlink" title="Marvel"></a>Marvel</h3><p>Marvel用来监控 Elasticsearch 集群实时、历史状态的有力用具，便于性能优化以及故障诊断。</p>
<p>监控主要分为六个层面，分别是集群层、节点层、索引层、分片层、事件层、Sense，在开发环境下免费使用。</p>
<figure class="highlight angelscript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">./bin/plugin -i elasticsearch/marvel/latest</span><br><span class="line">Kibana</span><br><span class="line"></span><br><span class="line">Kibana是一个用于ElasticSearch分析和查询的仪表盘。</span><br><span class="line"></span><br><span class="line">tar zxvf kibana<span class="number">-4.5</span><span class="number">.0</span>-linux-x64.tar.gz</span><br><span class="line">cd ./kibana<span class="number">-4.5</span><span class="number">.0</span>-linux-x64/bin/</span><br><span class="line">./kibana</span><br></pre></td></tr></table></figure>

<p>可以通过下行命令来查看节点上的插件列表</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">curl http://localhost:9200/_nodes/_local/plugins</span><br></pre></td></tr></table></figure>

<h2 id="Elasticsearch-配置"><a href="#Elasticsearch-配置" class="headerlink" title="Elasticsearch 配置"></a>Elasticsearch 配置</h2><p>config/elasticsearch.yml</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># ---------------------------------- Cluster -----------------------------------</span></span><br><span class="line"><span class="comment">#</span></span><br><span class="line"><span class="comment"># Use a descriptive name for your cluster:</span></span><br><span class="line"><span class="comment">#</span></span><br><span class="line"> <span class="attr">cluster.name:</span> <span class="string">ela</span></span><br><span class="line"><span class="comment">#</span></span><br><span class="line"><span class="comment"># ------------------------------------ Node ------------------------------------</span></span><br><span class="line"><span class="comment">#</span></span><br><span class="line"><span class="comment"># Use a descriptive name for the node:</span></span><br><span class="line"><span class="comment">#</span></span><br><span class="line"> <span class="attr">node.name:</span> <span class="string">node-1</span></span><br><span class="line"><span class="comment">#</span></span><br><span class="line"><span class="comment"># Add custom attributes to the node:</span></span><br><span class="line"><span class="comment">#</span></span><br><span class="line"><span class="comment"># node.rack: r1</span></span><br><span class="line"><span class="comment"># ---------------------------------- Network -----------------------------------</span></span><br><span class="line"><span class="comment">#</span></span><br><span class="line"><span class="comment"># Set the bind address to a specific IP (IPv4 or IPv6):</span></span><br><span class="line"><span class="comment">#</span></span><br><span class="line"> <span class="attr">network.host:</span> <span class="number">0.0</span><span class="number">.0</span><span class="number">.0</span></span><br><span class="line"><span class="comment">#</span></span><br><span class="line"><span class="comment"># Set a custom port for HTTP:</span></span><br><span class="line"><span class="comment">#</span></span><br><span class="line"><span class="comment"># http.port: 9200</span></span><br><span class="line"><span class="comment">#</span></span><br><span class="line"><span class="comment"># For more information, see the documentation at:</span></span><br><span class="line"><span class="comment"># &lt;http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html&gt;</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># personal setting,use for http post add new field</span></span><br><span class="line"> <span class="attr">script.update:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">script.mapping:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">script.engine.groovy.file.aggs:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">script.engine.groovy.file.mapping:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">script.engine.groovy.file.search:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">script.engine.groovy.file.update:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">script.engine.groovy.file.plugin:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">script.engine.groovy.indexed.aggs:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">script.engine.groovy.indexed.mapping:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">script.engine.groovy.indexed.search:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">script.engine.groovy.indexed.update:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">script.engine.groovy.indexed.plugin:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">script.engine.groovy.inline.aggs:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">script.engine.groovy.inline.mapping:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">script.engine.groovy.inline.search:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">script.engine.groovy.inline.update:</span> <span class="literal">true</span></span><br><span class="line"> <span class="attr">script.engine.groovy.inline.plugin:</span> <span class="literal">true</span></span><br></pre></td></tr></table></figure>

<p> <code>cluster.name</code>：保存集群的名字，不同的集群用名字来区分，配置成相同集群名字的各个节点形成一个集群。节点启动时据此自动加入对应的集群，如果集群存在的话。</p>
<p><code>node.name</code>：实例（该节点）的名字，可以不定义此参数，这时，Elasticsearch自动选择一个唯一的名称。注意，此名称是每次启动时选择的，所以在每次重启后名称可能都不一样。在很长的时间区间或者重启过后，需要在API中提及具体实例名称，或者用监控工具查看节点，自定义一个名称还是很有帮助的。</p>
<p><code>http.port</code>：HTTP API的默认端口号是9200，Elasticsearch很聪明，如果默认端口不可用，引擎将绑定到下一个可用端口。</p>
<p><code>network.bind_host</code>：默认情况下 Elasticsearch 的 RESTful 服务只有本机才能访问，也就是说无法从主机访问虚拟机中的服务，可以设置为0.0.0.0以方便主机调式虚拟机。</p>
<h2 id="Reference"><a href="#Reference" class="headerlink" title="Reference"></a>Reference</h2><ul>
<li><a href="https://www.elastic.co/guide/en/elasticsearch/reference/2.3/index.html" target="_blank" rel="noopener">ES2.3官方文档</a></li>
</ul>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

        
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://codz-me.vercel.app/2016/05/26/music-always-quiet-asang/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/head.png">
      <meta itemprop="name" content="laudukang">
      <meta itemprop="description" content="Bug Not Found">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Code Is Poetry">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          
            <a href="/2016/05/26/music-always-quiet-asang/" class="post-title-link" itemprop="url">一直很安静-阿桑.ape</a>
        </h1>

        <div class="post-meta">
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2016-06-04 18:00:02 18:00:02" itemprop="dateModified" datetime="2016-06-04T18:00:02+08:00">2016-06-04 18:00:02</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Life/" itemprop="url" rel="index">
                    <span itemprop="name">Life</span>
                  </a>
                </span>
            </span>

          
            <span id="/2016/05/26/music-always-quiet-asang/" class="post-meta-item leancloud_visitors" data-flag-title="一直很安静-阿桑.ape" title="阅读次数">
                <span hidden class="leancloud-visitors-count"></span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h2 id="在线播放"><a href="#在线播放" class="headerlink" title="在线播放"></a>在线播放</h2><ul>
<li><a href="http://www.kugou.com/song/#hash=7D4F2C26551CC9431444D782D607E65B&album_id=972917" target="_blank" rel="noopener">一直很安静-阿桑-酷狗</a></li>
</ul>
<h2 id="歌词"><a href="#歌词" class="headerlink" title="歌词"></a>歌词</h2><blockquote><p>阿桑 - 一直很安静<br>空荡的街景<br>想找个人放感情<br>作这种决定<br>是寂寞与我为邻<br>我们的爱情<br>像你路过的风景<br>一直在进行<br>脚步却从来不会为我而停<br>给你的爱一直很安静<br>来交换你偶尔给的关心<br>明明是三个人的电影<br>我却始终不能有姓名<br>你说爱像云<br>要自在飘浮才美丽<br>我终于相信<br>分手的理由有时候很动听<br>给你的爱一直很安静<br>来交换你偶尔给的关心<br>明明是三个人的电影<br>我却始终不能有姓名<br>给你的爱一直很安静<br>我从一开始就下定决心<br>以为自己要的是曾经<br>却发现爱一定要有回应<br>给你的爱一直很安静<br>来交换你偶尔给的关心<br>明明是三个人的电影<br>我却始终不能有姓名<br>给你的爱一直很安静<br>除了泪在我的脸上任性<br>原来缘分是用来说明<br>你突然不爱我这件事情</p>
</blockquote>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

        
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://codz-me.vercel.app/2016/03/23/idea-config-tomcat-virtual-directory/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/head.png">
      <meta itemprop="name" content="laudukang">
      <meta itemprop="description" content="Bug Not Found">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Code Is Poetry">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          
            <a href="/2016/03/23/idea-config-tomcat-virtual-directory/" class="post-title-link" itemprop="url">IDEA 配置 Tomcat 虚拟路径</a>
        </h1>

        <div class="post-meta">
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2016-03-23 14:17:13 14:17:13" itemprop="dateModified" datetime="2016-03-23T14:17:13+08:00">2016-03-23 14:17:13</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Java/" itemprop="url" rel="index">
                    <span itemprop="name">Java</span>
                  </a>
                </span>
            </span>

          
            <span id="/2016/03/23/idea-config-tomcat-virtual-directory/" class="post-meta-item leancloud_visitors" data-flag-title="IDEA 配置 Tomcat 虚拟路径" title="阅读次数">
                <span hidden class="leancloud-visitors-count"></span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>与Myeclipse略不同，除了在<code>Tomcat/conf/server.xml</code>的Host节点下指定外</p>
<figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;Context <span class="attribute">path</span>=<span class="string">"/upload"</span> <span class="attribute">docBase</span>=<span class="string">"D:\apache\online_submission\upload"</span> /&gt;</span><br></pre></td></tr></table></figure>

<p>还需要在IDEA的</p>
<p><code>Run/Debug Configurations - Tomcat Server - Server -Tomcat Server Settings</code></p>
<p>勾选</p>
<p><code>Deploy applications configured in Tomcat instance</code></p>
<img src="/2016/03/23/idea-config-tomcat-virtual-directory/idea.png" alt="idea.png" title="">

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

        
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://codz-me.vercel.app/2016/03/22/spring-modelattribute-and-commandname-atributes/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/head.png">
      <meta itemprop="name" content="laudukang">
      <meta itemprop="description" content="Bug Not Found">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Code Is Poetry">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          
            <a href="/2016/03/22/spring-modelattribute-and-commandname-atributes/" class="post-title-link" itemprop="url">modelAttribute and commandName atributes in form tag in Spring</a>
        </h1>

        <div class="post-meta">
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2016-03-31 13:10:47 13:10:47" itemprop="dateModified" datetime="2016-03-31T13:10:47+08:00">2016-03-31 13:10:47</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Java/" itemprop="url" rel="index">
                    <span itemprop="name">Java</span>
                  </a>
                </span>
            </span>

          
            <span id="/2016/03/22/spring-modelattribute-and-commandname-atributes/" class="post-meta-item leancloud_visitors" data-flag-title="modelAttribute and commandName atributes in form tag in Spring" title="阅读次数">
                <span hidden class="leancloud-visitors-count"></span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>查了一些源码，发现<code>commandName</code>其实是set get <code>modelAttribute</code>的<code>org.springframework.web.servlet.tags.form.FormTag</code></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">FormTag</span> <span class="keyword">extends</span> <span class="title">AbstractHtmlElementTag</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//other codes</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">/** The default attribute name: &amp;quot;command&amp;quot; */</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">final</span> String DEFAULT_COMMAND_NAME = <span class="string">"command"</span>;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">private</span> String modelAttribute = DEFAULT_COMMAND_NAME;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * Set the name of the form attribute in the model.</span></span><br><span class="line"><span class="comment">     * &lt;p&gt;May be a runtime expression.</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setModelAttribute</span><span class="params">(String modelAttribute)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.modelAttribute = modelAttribute;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * Get the name of the form attribute in the model.</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">protected</span> String <span class="title">getModelAttribute</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">this</span>.modelAttribute;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * Set the name of the form attribute in the model.</span></span><br><span class="line"><span class="comment">     * &lt;p&gt;May be a runtime expression.</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@see</span> #setModelAttribute</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setCommandName</span><span class="params">(String commandName)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.modelAttribute = commandName;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * Get the name of the form attribute in the model.</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@see</span> #getModelAttribute</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">protected</span> String <span class="title">getCommandName</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">this</span>.modelAttribute;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//other codes</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

        
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://codz-me.vercel.app/2016/03/12/idea-project-language-level-auto-change-to-1_6/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/head.png">
      <meta itemprop="name" content="laudukang">
      <meta itemprop="description" content="Bug Not Found">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Code Is Poetry">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          
            <a href="/2016/03/12/idea-project-language-level-auto-change-to-1_6/" class="post-title-link" itemprop="url">解决IDEA自动重置Project Language Level为1.6</a>
        </h1>

        <div class="post-meta">
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2016-03-12 19:09:44 19:09:44" itemprop="dateModified" datetime="2016-03-12T19:09:44+08:00">2016-03-12 19:09:44</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Java/" itemprop="url" rel="index">
                    <span itemprop="name">Java</span>
                  </a>
                </span>
            </span>

          
            <span id="/2016/03/12/idea-project-language-level-auto-change-to-1_6/" class="post-meta-item leancloud_visitors" data-flag-title="解决IDEA自动重置Project Language Level为1.6" title="阅读次数">
                <span hidden class="leancloud-visitors-count"></span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>IDEA 导入的 Maven 项目默认的 LanguageLeve l和 JavaCompiler 都是1.5，解决办法是在<code>pom.xml</code>中指定<code>maven-compiler-plugin</code>的版本</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">build</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">plugins</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">plugin</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.apache.maven.plugins<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>maven-compiler-plugin<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">version</span>&gt;</span>2.3.2<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">configuration</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">source</span>&gt;</span>1.8<span class="tag">&lt;/<span class="name">source</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">target</span>&gt;</span>1.8<span class="tag">&lt;/<span class="name">target</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;/<span class="name">configuration</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">plugin</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">plugins</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">build</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>reference:</p>
<ul>
<li><a href="http://stackoverflow.com/questions/27037657/stop-intellij-idea-to-switch-java-language-level-everytime-the-pom-is-reloaded" target="_blank" rel="noopener">stop intellij idea to switch java language level everytime the pom is reloaded (or change the default project language level)</a></li>
</ul>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

  </div>

  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/"><i class="fa fa-angle-left" aria-label="上一页"></i></a><a class="page-number" href="/">1</a><span class="page-number current">2</span><a class="page-number" href="/page/3/">3</a><span class="space">&hellip;</span><a class="page-number" href="/page/7/">7</a><a class="extend next" rel="next" href="/page/3/"><i class="fa fa-angle-right" aria-label="下一页"></i></a>
  </nav>



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let activeClass = CONFIG.comments.activeClass;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="laudukang"
      src="/images/head.png">
  <p class="site-author-name" itemprop="name">laudukang</p>
  <div class="site-description" itemprop="description">Bug Not Found</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">68</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">10</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">25</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/laudukang" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;laudukang" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://gitee.com/laudukang" title="Gitee → https:&#x2F;&#x2F;gitee.com&#x2F;laudukang" rel="noopener" target="_blank"><i class="fa fa-fw fa-github-alt"></i>Gitee</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://stackoverflow.com/users/5621049/laudukang" title="StackOverflow → https:&#x2F;&#x2F;stackoverflow.com&#x2F;users&#x2F;5621049&#x2F;laudukang" rel="noopener" target="_blank"><i class="fa fa-fw fa-stack-overflow"></i>StackOverflow</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://www.google.com/maps/place/%E6%B7%B1%E5%9C%B3%E5%B8%82%E8%BD%AF%E4%BB%B6%E4%BA%A7%E4%B8%9A%E5%9F%BA%E5%9C%B0/@22.5244896,113.9382973,17z/data=!3m1!4b1!4m5!3m4!1s0x3403ee17d008a019:0xbb7b06b73d856c14!8m2!3d22.5244896!4d113.9382973" title="Map → https:&#x2F;&#x2F;www.google.com&#x2F;maps&#x2F;place&#x2F;%E6%B7%B1%E5%9C%B3%E5%B8%82%E8%BD%AF%E4%BB%B6%E4%BA%A7%E4%B8%9A%E5%9F%BA%E5%9C%B0&#x2F;@22.5244896,113.9382973,17z&#x2F;data&#x3D;!3m1!4b1!4m5!3m4!1s0x3403ee17d008a019:0xbb7b06b73d856c14!8m2!3d22.5244896!4d113.9382973" rel="noopener" target="_blank"><i class="fa fa-fw fa-map-marker"></i>Map</a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

<div class="copyright">
  
  &copy; 2015 – 
  <span itemprop="copyrightYear">2025</span>
  <span class="with-love">
    <i class="fa fa-heart icon-next-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">laudukang</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> 强力驱动 v4.2.0
  </div>
  <span class="post-meta-divider">|</span>
  <div class="theme-info">主题 – <a href="https://muse.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a> v7.7.1
  </div>

        
<div class="busuanzi-count">
  <script pjax async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
</div>






  <script pjax>
  function leancloudSelector(url) {
    url = encodeURI(url);
    return document.getElementById(url).querySelector('.leancloud-visitors-count');
  }
  if (CONFIG.page.isPost) {
    function addCount(Counter) {
      var visitors = document.querySelector('.leancloud_visitors');
      var url = decodeURI(visitors.getAttribute('id'));
      var title = visitors.getAttribute('data-flag-title');

      Counter('get', `/classes/Counter?where=${JSON.stringify({ url })}`)
        .then(response => response.json())
        .then(({ results }) => {
          if (results.length > 0) {
            var counter = results[0];
              leancloudSelector(url).innerText = counter.time + 1;
            Counter('put', '/classes/Counter/' + counter.objectId, { time: { '__op': 'Increment', 'amount': 1 } })
              .then(response => response.json())
              .catch(error => {
                console.error('Failed to save visitor count', error);
              })
          } else {
              Counter('post', '/classes/Counter', { title: title, url: url, time: 1 })
                .then(response => response.json())
                .then(() => {
                  leancloudSelector(url).innerText = 1;
                })
                .catch(error => {
                  console.error('Failed to create', error);
                });
          }
        })
        .catch(error => {
          console.error('LeanCloud Counter Error', error);
        });
    }
  } else {
    function showTime(Counter) {
      var visitors = document.querySelectorAll('.leancloud_visitors');
      var entries = [...visitors].map(element => {
        return decodeURI(element.getAttribute('id'));
      });

      Counter('get', `/classes/Counter?where=${JSON.stringify({ url: { '$in': entries } })}`)
        .then(response => response.json())
        .then(({ results }) => {
          if (results.length === 0) {
            document.querySelectorAll('.leancloud_visitors .leancloud-visitors-count').forEach(element => {
              element.innerText = 0;
            });
            return;
          }
          for (let item of results) {
            let { url, time } = item;
            leancloudSelector(url).innerText = time;
          }
          for (let url of entries) {
            var element = leancloudSelector(url);
            if (element.innerText == '') {
              element.innerText = 0;
            }
          }
        })
        .catch(error => {
          console.error('LeanCloud Counter Error', error);
        });
    }
  }

  fetch('https://app-router.leancloud.cn/2/route?appId=CPfRDhOlTyfkHW155W3Kx3H1-gzGzoHsz')
    .then(response => response.json())
    .then(({ api_server }) => {
      var Counter = (method, url, data) => {
        return fetch(`https://${api_server}/1.1${url}`, {
          method: method,
          headers: {
            'X-LC-Id': 'CPfRDhOlTyfkHW155W3Kx3H1-gzGzoHsz',
            'X-LC-Key': 'TX05RQSQMd8fbL7RaJNADS7S',
            'Content-Type': 'application/json',
          },
          body: JSON.stringify(data)
        });
      };
      if (CONFIG.page.isPost) {
        if (CONFIG.hostname !== location.hostname) return;
        addCount(Counter);
      } else if (document.querySelectorAll('.post-title-link').length >= 1) {
        showTime(Counter);
      }
    });
  </script>


      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/pjax/pjax.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
  <script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>

  <script>
var pjax = new Pjax({
  selectors: [
    'head title',
    '#page-configurations',
    '.content-wrap',
    '.post-toc-wrap',
    '#pjax'
  ],
  switches: {
    '.post-toc-wrap': Pjax.switches.innerHTML
  },
  analytics: false,
  cacheBust: false,
  scrollTo : !CONFIG.bookmark.enable
});

window.addEventListener('pjax:success', () => {
  document.querySelectorAll('script[pjax], script#page-configurations, #pjax script').forEach(element => {
    var code = element.text || element.textContent || element.innerHTML || '';
    var parent = element.parentNode;
    parent.removeChild(element);
    var script = document.createElement('script');
    if (element.id) {
      script.id = element.id;
    }
    if (element.className) {
      script.className = element.className;
    }
    if (element.type) {
      script.type = element.type;
    }
    if (element.src) {
      script.src = element.src;
      // Force synchronous loading of peripheral JS.
      script.async = false;
    }
    if (element.getAttribute('pjax') !== null) {
      script.setAttribute('pjax', '');
    }
    if (code !== '') {
      script.appendChild(document.createTextNode(code));
    }
    parent.appendChild(script);
  });
  NexT.boot.refresh();
  // Define Motion Sequence & Bootstrap Motion.
  if (CONFIG.motion.enable) {
    NexT.motion.integrator
      .init()
      .add(NexT.motion.middleWares.subMenu)
      .add(NexT.motion.middleWares.postList)
      .bootstrap();
  }
  NexT.utils.updateSidebarPosition();
});
</script>




  















    <div id="pjax">
  

  
<script>window.va = window.va || function () { (window.vaq = window.vaq || []).push(arguments); };</script><script defer src="/_vercel/insights/script.js" data-endpoint="/this-is-vercel-insights"></script><script>window.si = window.si || function () { (window.siq = window.siq || []).push(arguments); };</script><script defer src="/_vercel/speed-insights/script.js" data-endpoint="/this-is-vercel-insights-speed"></script>
    </div>
</body>
</html>
